package com.dianwoba.core.search;

import java.io.Serializable;

/**
 * @author Zhu
 * @date 2015-5-14
 * @version 0.0.1
 * @description
 */
@SuppressWarnings("serial")
public class PagingSearchable implements Searchable, Serializable {
	
	public final static int MAX_PAGE = 999999999;

	private Integer currentPage = 1;
	private Integer perPage = 10;
	private boolean paging = true;
	private String orderByClause;
	private int offset;

	/**
	 * @return the currentPage
	 */
	public Integer getCurrentPage() {
		return currentPage;
	}

	/**
	 * @param currentPage
	 *            the currentPage to set
	 */
	public void setCurrentPage(Integer currentPage) {
		this.currentPage = currentPage;
	}

	/**
	 * @return the perPage
	 */
	public Integer getPerPage() {
		return perPage;
	}

	/**
	 * @param perPage
	 *            the perPage to set
	 */
	public void setPerPage(Integer perPage) {
		this.perPage = perPage;
	}

	public Integer getBegin() {
		if (isPaging()) {
			return (currentPage - 1) * perPage + offset;
		}
		return 0;
	}

	/**
	 * @return the paging
	 */
	public boolean isPaging() {
		return paging;
	}

	/**
	 * @param paging
	 *            the paging to set
	 */
	public void setPaging(boolean paging) {
		this.paging = paging;
	}

	/**
	 * @return the orderByClause
	 */
	public String getOrderByClause() {
		return orderByClause;
	}

	/**
	 * @param orderByClause
	 *            the orderByClause to set
	 */
	public void setOrderByClause(String orderByClause) {
		this.orderByClause = orderByClause;
	}

	/**
	 * @return the offset
	 */
	public int getOffset() {
		return offset;
	}

	/**
	 * @param offset
	 *            the offset to set
	 */
	public void setOffset(int offset) {
		this.offset = offset;
	}

}
